<?php

namespace common\models\shop;

use Yii;
use common\models\shop\Store;
use yii\db\ActiveRecord;

/**
 * Desc 员工
 */
class Clerk extends ActiveRecord {

    //总店
    const TYPE_MAIN_STORE = 1;
    //分店
    const TYPE_BRANCH_STORE = 2;
    //职位-商户(老板)
    const POSITION_BOSS = 1;
    //职位-店长
    const POSITION_MANAGER = 2;
    //职位-店员
    const POSITION_CLERK = 3;
    //状态-启用
    const STATUS_ENABLE = 1;
    //状态-禁用
    const STATUS_DISABLE = 2;

    public static $position = [
        self::POSITION_BOSS => 'BOSS',
        self::POSITION_MANAGER => '店长',
        self::POSITION_CLERK => '店员',
    ];
    public static $type = [
        self::TYPE_MAIN_STORE => '总店',
        self::TYPE_BRANCH_STORE => '分店',
    ];
    public static $status = [
        self::STATUS_ENABLE => '启用',
        self::STATUS_DISABLE => '禁用',
    ];

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%pay_clerk}}';
    }

    /**
     * 员工登录数据
     * * */
    public static function getClerkLoginInfo($account) {
        return Store::find()->alias('store')
                        ->select([
                            'store.id',
                            'store.mer_id',
                            'store.name',
                            'store.type',
                            'store.contacts',
                            'store.phone',
                            'store.province',
                            'store.city',
                            'store.area',
                            'store.address',
                            'store.address',
                            'clerk.store_id',
                            'clerk.id as clerk_id',
                            'clerk.name as clerk_name',
                            'clerk.position',
                            'clerk.status',
                            'clerk.password',
                            'clerk.create_time',
                        ])
                        ->leftJoin(self::tableName() . ' as clerk', 'store.id = clerk.store_id')
                        ->where(['OR', ['=', 'store.phone', $account],['=', 'clerk.phone', $account]])
                        ->asArray()
                        ->one();
    }

}
